package com.doraz.orb.methods.computer;

import java.io.InputStream;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import com.doraz.orb.Constants;
import com.doraz.orb.methods.OrbMethod;
import com.doraz.orb.structs.Computer;
import com.doraz.orb.structs.OrbObject;
import com.doraz.orb.utils.IntValidator;
import com.doraz.orb.utils.XMLUtils;

public class GetOnlineStatus extends OrbMethod {

	/**
	 * Gets the status of the user's computer
	 */
	public GetOnlineStatus() {
		super("computer.getOnlineStatus", "xml/computer.getOnlineStatus", Constants.RETURN_XML);		
	}
	
	@Override
	public OrbObject parseResponse(InputStream in) {
		Computer comp = null;
		Document doc = XMLUtils.getDocument(in);
		if(doc == null) {
			throw new IllegalArgumentException("Invalid Input Stream");
		}
		
		NodeList children = doc.getElementsByTagName("onlineStatus");
		if(children.getLength() > 0) {
			comp = XMLUtils.parseComputer((Element) children.item(0));
		}
		else {
			throw new IllegalArgumentException("Invalid Response from Server");
		}
		
		return comp;
	}

}
